home *** CD-ROM | disk | FTP | other *** search
- /*
- $VER: SafeEdit.thor 1.3 (19.10.98)
- by Neil Bothwick
- */
- /*
- Freezes an event before starting the editor, to prevent
- unedited mails being sent out
-
- You must define your editor command in ENVARC:THOR/Editor
- The editor *must* be started with s sticky option, or the
- script will fail to work as needed
-
- 1.1 Added check on whether file had been altered on exit
-
- 1.2 Added ADDUSER switch to add the recipient to the User Database
-
- 1.3 The script was assuming rexxdossupport.library was already
- available, thnks to Gian Maria Calzolari for pointing this out
- */
-
-
- options results
- parse arg arguments
-
- /* ;;; Read edit command */
- if ~open(ec,'ENV:THOR/Editor','R') then call ExitMsg('Unable to read ENV:THOR/Editor*NHave you set it?')
- EditCmd = readln(ec)
- call close(ec)
- ;;;
- /* ;;; Make sure bbsread.library and rexxdossupport.library are accessible from arexx */
- if ~show('p', 'BBSREAD') then do
- address command
- 'run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead'
- 'WaitForPort BBSREAD'
- end
- if ~show('L','rexxdossupport.library') then do
- if ~addlib('rexxdossupport.library',0,-30,0) then call ExitMsg('Failed to open rexxdossupport.library')
- end
- ;;;
- /* ;;; Get Thor arexx port and system name */
- portlist = ' '||show('P')
- thorpos = pos(' THOR.',portlist)
- if thorpos = 0 then call ExitMsg('SafeEd must be called from within Thor')
- parse var portlist t1 =thorpos thorport .
- address(thorport)
- drop TMP.
- 'CURRENTSYSTEM stem TMP'
- SystemName = TMP.BBSNAME
- ;;;
- /* ;;; Parse arguments */
- drop ARGS.
- template = 'TEXTFILE/A,ADDUSER/S'
- address BBSREAD
- 'READARGS' template 'ARGS CMDLINE' arguments
- AddUser = ARGS.ADDUSER
- TextFile = ARGS.TEXTFILE
- ;;;
- /* ;;; Search event list for event number */
- address BBSREAD
- GETBBSDATA SystemName SystemData
- EventFound = 0
- do EventNo = SystemData.LASTEVENT to SystemData.FIRSTEVENT by -1
- drop EventData.
- drop EventTags.
- READBREVENT '"'SystemName'"' eventnr EventNo tagsstem EventTags
- if SystemData.BBSPATH||EventTags.MSGFILE = TextFile then do
- EventFound = 1
- leave
- end
- end
- if EventFound = 0 then call ExitMsg('Event not found')
- ;;;
-
- /* ;;; Add user to database if required */
- if AddUser = 1 then do
- address 'BBSREAD'
- drop USER.
- USER.NAME = EventTags.TONAME
- USER.ADDRESS = EventTags.TOADDR
- USER.COMMENT.COUNT = 1
- USER.COMMENT.1 = 'Added by SafeEdit'
- 'WRITEBRUSER bbsname "'SystemName'" stem USER ONLYIFEXIST'
- end
- ;;;
- /* ;;; Freeze event, run editor synchronously, then unfreeze it */
-
- del = 0
- TimeStamp = subword(statef(TextFile),5,3)
- UPDATEBREVENT '"'SystemName'"' EventNo SETFREEZE
- do forever
- address command EditCmd TextFile
- if subword(statef(TextFile),5,3) ~= TimeStamp then leave
- address(thorport)
- 'REQUESTNOTIFY "Message text has not been saved" "_Edit|_Delete|_Continue"'
- response = result
- if response = 2 then Del = 1
- if response ~= 1 then leave
- end
-
- address BBSREAD
- if Del = 1 then 'UPDATEBREVENT "'SystemName'"' EventNo 'SETDELETED'
- else 'UPDATEBREVENT "'SystemName'"' EventNo 'CLEARFREEZE'
- ;;;
-
- exit
-
- /* ;;; Exit with a message */
- ExitMsg:
- parse arg msg
- address command 'RequestChoice >NIL: "SafeEdit" "'msg'" "Continue"'
- exit
- return
- ;;;
-
-